package org.yray.neo4j.hanlp;

import com.hankcs.hanlp.seg.common.Term;
import lombok.Data;
import java.util.HashSet;
import java.util.Set;


@Data
public class ScoreEntity implements Comparable<ScoreEntity> {

    private int score;
    private String id;
    private int distance;
    private int sum;
    private String question;
    private Set<String> termSet;

    public void calScore(TermEntity termEntity, Term qTerm)
    {
        if(!termSet.contains(qTerm.word)) {
            this.score += termEntity.getScore();
            this.distance += Math.pow(qTerm.offset - termEntity.getTerm().offset, 2);
            this.sum++;
            termSet.add(qTerm.word);
        }
    }



    public ScoreEntity(String id,String question)
    {
        this.id=id;
        this.score=0;
        this.distance=0;
        this.sum=0;
        this.question=question;
        this.termSet=new HashSet<>();
    }

    @Override
    public int compareTo(ScoreEntity o) {
        int result=o.score-this.score;
        if(result==0)
        {
            result=this.distance/this.sum-o.distance/o.sum;
            if(result==0)
            {
                return question.length()-o.getQuestion().length();
            }
        }
        return result;

    }


}
